from django.db import models

# Create your models here.
from datetime import datetime


class Course(models.Model):
    name = models.CharField(max_length=50, verbose_name=u'课程名')
    desc = models.CharField(max_length=300, verbose_name=u'课程描述')
    detail = models.TextField(verbose_name=u'课程详情')
    degree = models.CharField(choices=(('cj', '初级'), ('zj', '中级'), ('gj', '高级')), max_length=2, verbose_name=u'等级')
    learn_times = models.IntegerField(default=0, verbose_name='学习时长(分钟数)')
    students = models.IntegerField(default=0, verbose_name=u'学习人数')
    fav_nums = models.IntegerField(default=0, verbose_name=u'收藏人数')
    image = models.ImageField(upload_to='courses/%Y/%m', verbose_name='封面图', max_length=100)
    click_nums = models.IntegerField(default=0,verbose_name='点击数')
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'课程'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Lesson(models.Model):
    courseId = models.ForeignKey(Course, verbose_name=u'课程', on_delete=models.CASCADE)
    name = models.CharField(max_length=100, verbose_name=u'章节名')
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'章节'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Video(models.Model):
    lessonId = models.ForeignKey(Lesson, verbose_name=u'课程', on_delete=models.CASCADE)
    name = models.CharField(max_length=100, verbose_name=u'视频名')
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'视频'
        verbose_name_plural = verbose_name


class CourseResource(models.Model):
    courseId = models.ForeignKey(Course, verbose_name=u'课程', on_delete=models.CASCADE)
    name = models.CharField(max_length=100, verbose_name=u'名称')
    download = models.FileField(upload_to='course/resource/%Y/%m', verbose_name=u'资源文件', max_length=100)
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'课程资源'
        verbose_name_plural = verbose_name

